package com.example.zhugenew.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mymvplibrary.ui.activity.BaseActivity;
import com.example.zhugenew.MVP.presenter.IPrensenter;
import com.example.zhugenew.MVP.view.IView;
import com.example.zhugenew.R;
import com.example.zhugenew.adapter.newhouses.NewHouseBlockAdapter;
import com.example.zhugenew.adapter.newhouses.NewHouseEvidenceAdapter;
import com.example.zhugenew.adapter.newhouses.NewHouseHotlistAdapter;
import com.example.zhugenew.adapter.newhouses.NewHouseListAdapter;
import com.example.zhugenew.bean.newhouses.NewHouseBlockBean;
import com.example.zhugenew.bean.newhouses.NewHouseEvidenceBean;
import com.example.zhugenew.bean.newhouses.NewHouseHotListBean;
import com.example.zhugenew.bean.newhouses.NewHouseImageBean;
import com.example.zhugenew.bean.newhouses.NewListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class NewHouseActivity<T> extends BaseActivity implements IView {


    @BindView(R.id.new_house_recl_block)
    RecyclerView newHouseReclBlock;
    @BindView(R.id.new_house_image)
    ImageView newHouseImage;
    @BindView(R.id.new_house_btnfan)
    Button newHouseBtnfan;
    @BindView(R.id.new_house_recl_evidence)
    RecyclerView newHouseReclEvidence;
    @BindView(R.id.new_house_recl_hotlist)
    RecyclerView newHouseReclHotlist;
    @BindView(R.id.new_house_recy_lou)
    RecyclerView newHouseRecyLou;
    private IPrensenter iPrensenter;
    private NewHouseBlockAdapter newHouseBlockAdapter;

    @Override
    protected void initData() {
        iPrensenter = new IPrensenter(this);
        iPrensenter.getBlockData();
        iPrensenter.getImageData();
        iPrensenter.getEvidenceData();
        iPrensenter.getHotlistData();
        iPrensenter.getNewListData();
        newHouseBtnfan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected int createLayoutId() {
        return R.layout.activity_new_house;
    }

    @Override
    public void blockSuccess(NewHouseBlockBean newHouseBlockBean) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        newHouseReclBlock.setLayoutManager(linearLayoutManager);

        newHouseBlockAdapter = new NewHouseBlockAdapter(newHouseBlockBean, this);
        newHouseReclBlock.setAdapter(newHouseBlockAdapter);
        newHouseBlockAdapter.notifyDataSetChanged();
        Log.e("TAG", "blockSuccess: " + newHouseBlockBean.getData());
    }

    @Override
    public void imageSuccess(NewHouseImageBean newHouseImageBean) {
//        List<NewHouseImageBean.DataBean> data = newHouseImageBean.getData();
//        for (int i = 0; i < data.size(); i++) {
//        }
//        String url = data.get(0).getImage().getCommon().getUrl();
//        String url = newHouseImageBean.getData().get(0).getImage().getCommon().getUrl();
//        Glide.with(this).load(url).into(newHouseImage);
    }

    @Override
    public void evidenceSuccess(NewHouseEvidenceBean newHouseEvidenceBean) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        newHouseReclEvidence.setLayoutManager(linearLayoutManager);
        List<NewHouseEvidenceBean.DataBean> data = newHouseEvidenceBean.getData();
        NewHouseEvidenceAdapter newHouseEvidenceAdapter = new NewHouseEvidenceAdapter(data, this);
        newHouseReclEvidence.setAdapter(newHouseEvidenceAdapter);
        newHouseEvidenceAdapter.notifyDataSetChanged();
        Log.e("TAG", "EvidenceSuccess: " + newHouseEvidenceBean.getData());
    }

    @Override
    public void hotlistSuccess(NewHouseHotListBean newHouseHotListBean) {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
        newHouseReclHotlist.setLayoutManager(gridLayoutManager);
        NewHouseHotlistAdapter newHouseHotlistAdapter = new NewHouseHotlistAdapter(newHouseHotListBean.getData(), this);
        newHouseReclHotlist.setAdapter(newHouseHotlistAdapter);
        newHouseHotlistAdapter.notifyDataSetChanged();
        Log.e("TAG", "hotlistSuccess: " + newHouseHotListBean.getData());
    }

    @Override
    public void newlistSuccess(NewListBean.DataBeanX newListBean) {
        newHouseRecyLou.setLayoutManager(new LinearLayoutManager(this));
        NewHouseListAdapter newHouseListAdapter = new NewHouseListAdapter(newListBean.getData(), this);
        newHouseRecyLou.setAdapter(newHouseListAdapter);
        newHouseListAdapter.notifyDataSetChanged();
        Log.e("TAG", "newlistSuccess: "+newListBean);
    }

    @Override
    public void showError(String error) {
        Log.e("TAG", "showError: " + error);
    }

    @Override
    public void showProgressbar() {

    }

    @Override
    public void hideProgressbar() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}